package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.lkx.liandianqinew.R;
import com.youyi.yyviewsdklibrary.View.MyMarkView;

public class MyZxingView extends RelativeLayout {
    private static final int DEFAULT_MARKED_COLOR = Color.parseColor("#00000000");
    private static final int DEFAULT_TINT_COLOR = Color.parseColor("#FFFFFF");
    private static final int DEFAULT_UNMARKED_COLOR = Color.parseColor("#80000000");
    private Context mContext;
    private Animation mHorizontalAnimation;
    private ImageView mImageViewH;
    private ImageView mImageViewV;
    private ImageView mImgSrc;
    private RelativeLayout mMainLayout;
    private Rect mMarkRect;
    private MyMarkView mMyMarkView;
    private int mPaddBottom;
    private int mSrc;
    private int mTintColor;
    private Animation mVerticalAnimation;
    private String mZxinTip;
    private int mZxingStyle;
    private TextView mZxingTip;

    public enum ZStyle {
        H,
        V,
        None
    }

    public MyZxingView(Context context) {
        super(context);
    }

    public MyZxingView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
//        this.mContext = context;
//        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MyZxingView);
//        this.mTintColor = obtainStyledAttributes.getColor(R.styleable.MyZxingView_yyZxingTintColor, DEFAULT_TINT_COLOR);
//        int color = obtainStyledAttributes.getColor(R.styleable.MyZxingView_yyZxingMarkColor, DEFAULT_MARKED_COLOR);
//        int color2 = obtainStyledAttributes.getColor(R.styleable.MyZxingView_yyZxingUnMarkColor, DEFAULT_UNMARKED_COLOR);
//        this.mZxingStyle = obtainStyledAttributes.getInt(R.styleable.MyZxingView_yyZxingStyle, 1);
//        String string = obtainStyledAttributes.getString(R.styleable.MyZxingView_yyZxingWidthPercent);
//        String string2 = obtainStyledAttributes.getString(R.styleable.MyZxingView_yyZxingHeightPercent);
//        this.mZxinTip = obtainStyledAttributes.getString(R.styleable.MyZxingView_yyZxingTip);
//        this.mSrc = obtainStyledAttributes.getResourceId(R.styleable.MyZxingView_yyZxingSrc, 0);
//        this.mPaddBottom = obtainStyledAttributes.getInt(R.styleable.MyZxingView_yyZxingTipPaddBottom, 0);
//        View inflate = LayoutInflater.from(context).inflate(R.layout._yy_my_zxing_view, (ViewGroup) this, true);
//        this.mMainLayout = (RelativeLayout) inflate.findViewById(R.id.id_main_layout);
//        this.mZxingTip = (TextView) inflate.findViewById(R.id.id_zxing_tip);
//        if (!TextUtils.isEmpty(this.mZxinTip)) {
//            this.mZxingTip.setText(this.mZxinTip);
//        }
//        this.mZxingTip.setPadding(0, 0, 0, this.mPaddBottom);
//        MyMarkView myMarkView = (MyMarkView) inflate.findViewById(R.id.id_markview);
//        this.mMyMarkView = myMarkView;
//        myMarkView.setConnerColor(this.mTintColor);
//        this.mMyMarkView.setMarkColor(color);
//        this.mMyMarkView.setUnmarkedColor(color2);
//        this.mMyMarkView.setPercent(string, string2);
//        this.mMyMarkView.getRect(new MyMarkView.OnRectListener() {
//            /* class com.youyi.yyviewsdklibrary.View.MyZxingView.AnonymousClass1 */
//
//            @Override // com.youyi.yyviewsdklibrary.View.MyMarkView.OnRectListener
//            public void result(Rect rect) {
//                MyZxingView.this.mMarkRect = rect;
//                MyZxingView.this.setStyle();
//                MyZxingView.this.showBg();
//            }
//        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void showBg() {
        ImageView imageView = this.mImgSrc;
        if (imageView != null) {
            this.mMainLayout.removeView(imageView);
            this.mImgSrc = null;
        }
        if (this.mSrc != 0) {
            this.mMyMarkView.getRect(new MyMarkView.OnRectListener() {
                /* class com.youyi.yyviewsdklibrary.View.MyZxingView.AnonymousClass2 */

                @Override // com.youyi.yyviewsdklibrary.View.MyMarkView.OnRectListener
                public void result(Rect rect) {
                    MyZxingView.this.mMarkRect = rect;
                    MyZxingView.this.mImgSrc = new ImageView(MyZxingView.this.mContext);
                    MyZxingView.this.mImgSrc.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    MyZxingView.this.mImgSrc.setColorFilter(MyZxingView.this.mTintColor);
                    LayoutParams layoutParams = new LayoutParams(MyZxingView.this.mMarkRect.width(), MyZxingView.this.mMarkRect.height());
                    layoutParams.addRule(13, -1);
                    MyZxingView.this.mImgSrc.setLayoutParams(layoutParams);
                    MyZxingView.this.mMainLayout.addView(MyZxingView.this.mImgSrc);
                    MyZxingView.this.mImgSrc.setImageResource(MyZxingView.this.mSrc);
                }
            });
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void setStyle() {
        this.mMyMarkView.getRect(new MyMarkView.OnRectListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyZxingView.AnonymousClass3 */

            @Override // com.youyi.yyviewsdklibrary.View.MyMarkView.OnRectListener
            public void result(Rect rect) {
                MyZxingView.this.mMarkRect = rect;
                MyZxingView.this.clearViewAndAnimation();
                int i = MyZxingView.this.mZxingStyle;
                if (i == 0) {
                    MyZxingView.this.mImageViewH = new ImageView(MyZxingView.this.mContext);
                    MyZxingView.this.mImageViewH.setImageResource(R.drawable._scan_line_v);
                    MyZxingView.this.mImageViewH.setColorFilter(MyZxingView.this.mTintColor);
                    MyZxingView.this.mImageViewH.setScaleType(ImageView.ScaleType.CENTER_CROP);
                    LayoutParams layoutParams = new LayoutParams(10, MyZxingView.this.mMarkRect.height());
                    layoutParams.addRule(13, -1);
                    MyZxingView.this.mImageViewH.setLayoutParams(layoutParams);
                    MyZxingView.this.mMainLayout.addView(MyZxingView.this.mImageViewH);
                    MyZxingView.this.mHorizontalAnimation = new TranslateAnimation((float) (-(MyZxingView.this.mMarkRect.width() / 2)), (float) ((MyZxingView.this.mMarkRect.width() / 2) - 5), 0.0f, 0.0f);
                    MyZxingView.this.mHorizontalAnimation.setDuration(3000);
                    MyZxingView.this.mHorizontalAnimation.setRepeatCount(-1);
                    MyZxingView.this.mImageViewH.setAnimation(MyZxingView.this.mHorizontalAnimation);
                    MyZxingView.this.mHorizontalAnimation.startNow();
                } else if (i == 1) {
                    MyZxingView.this.mImageViewV = new ImageView(MyZxingView.this.mContext);
                    MyZxingView.this.mImageViewV.setImageResource(R.drawable._scan_line_h);
                    MyZxingView.this.mImageViewV.setColorFilter(MyZxingView.this.mTintColor);
                    LayoutParams layoutParams2 = new LayoutParams(MyZxingView.this.mMarkRect.width(), 10);
                    layoutParams2.addRule(13, -1);
                    MyZxingView.this.mImageViewV.setLayoutParams(layoutParams2);
                    MyZxingView.this.mMainLayout.addView(MyZxingView.this.mImageViewV);
                    MyZxingView.this.mVerticalAnimation = new TranslateAnimation(0.0f, 0.0f, (float) ((-(MyZxingView.this.mMarkRect.height() / 2)) + 20), (float) ((MyZxingView.this.mMarkRect.height() / 2) - 20));
                    MyZxingView.this.mVerticalAnimation.setDuration(3000);
                    MyZxingView.this.mVerticalAnimation.setRepeatCount(-1);
                    MyZxingView.this.mImageViewV.setAnimation(MyZxingView.this.mVerticalAnimation);
                    MyZxingView.this.mVerticalAnimation.startNow();
                }
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clearViewAndAnimation() {
        ImageView imageView = this.mImageViewV;
        if (imageView != null) {
            if (imageView.getVisibility() == 0) {
                this.mMainLayout.removeView(this.mImageViewV);
                this.mImageViewV = null;
            }
            this.mImageViewV = null;
        }
        Animation animation = this.mVerticalAnimation;
        if (animation != null) {
            animation.cancel();
            this.mVerticalAnimation = null;
        }
        ImageView imageView2 = this.mImageViewH;
        if (imageView2 != null) {
            if (imageView2.getVisibility() == 0) {
                this.mMainLayout.removeView(this.mImageViewH);
            }
            this.mImageViewH = null;
        }
        Animation animation2 = this.mHorizontalAnimation;
        if (animation2 != null) {
            animation2.cancel();
            this.mHorizontalAnimation = null;
        }
    }

    public void setPercent(String str, String str2) {
        this.mMyMarkView.setPercent(str, str2);
        invalidate();
    }


    public void setZxingStyle(ZStyle zStyle) {
        int i = zStyle.ordinal();
        if (i == 1) {
            this.mZxingStyle = 0;
        } else if (i == 2) {
            this.mZxingStyle = 1;
        } else if (i == 3) {
            this.mZxingStyle = 2;
        }
        setStyle();
    }

    public void setSrc(int i) {
        this.mSrc = i;
        showBg();
    }

    public void setZxinTip(String str, int i) {
        this.mZxinTip = str;
        this.mPaddBottom = i;
        post(new Runnable() {
            /* class com.youyi.yyviewsdklibrary.View.MyZxingView.AnonymousClass4 */

            public void run() {
                MyZxingView.this.mZxingTip.setText(MyZxingView.this.mZxinTip);
                MyZxingView.this.mZxingTip.setPadding(0, 0, 0, MyZxingView.this.mPaddBottom);
            }
        });
    }
}
